package com.egao.orderB.controller;

import com.egao.common.core.annotation.ApiPageParam;
import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.*;
import com.egao.common.core.annotation.OperLog;
import com.egao.orderB.entity.DriverOil;
import com.egao.orderB.service.DriverOilService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.ui.Model;


/**
 *
 * 油卡
 * @author : Doman
 * @date : 2021-05-28 16:41:04
 * @version ：1.0
 */

@Api(tags = "油卡")
@RestController
@RequestMapping("/api/orderB/driverOil")
public class DriverOilController extends BaseController {

	@Autowired
	private DriverOilService driverOilService;

	/**
	 * 分页查询列表
	 */
	@PreAuthorize("hasAuthority('orderB:driverOil:list')")
    //@OperLog(value = "油卡", desc = "分页查询")
    @ApiOperation(value ="分页查询油卡",notes = "" +
        "driver 司机姓名\n" +
        "carNo 车牌\n" +
        "rechargeDate 油卡充值日期\n" +
        "返回\n\n\n" +
        "id:id\n" +
        "driverId:司机id\n" +
        "driver:司机姓名\n" +
        "carNo:车牌\n" +
        "oilCard:油卡号\n" +
        "usePrice: 油卡使用金额\n" +
        "balancePrice:油卡余额\n" +
        "rechargePrice:油卡当前充值金额\n" +
        "rechargeDate:油卡充值日期\n" +
        "cumulativePrice:油卡累计金额\n" +
        "remark:备注\n" +
        "createTime:创建时间\n" +
        "createUser:创建人\n" +
        "updateTime:更新时间\n" +
        "updateUser:更新人\n" +
        "",httpMethod = "POST")
    @ApiPageParam
    @PostMapping("/list")
    public JsonResult page(PageResult2<T> page, DriverOil driverOil) throws Exception{
        return driverOilService.list(page, driverOil, getLoginUser());
    }

    /**
     * 查询全部油卡
     */
    @PreAuthorize("hasAuthority('orderB:driverOil:list')")
    //@OperLog(value = "油卡", desc = "查询全部")
    @ApiOperation("查询全部油卡")
    @PostMapping("/listAll")
    public JsonResult list(DriverOil driverOil){
        return driverOilService.list(driverOil, getLoginUser());
    }

    /**
     * 根据id查询油卡
     */
    @PreAuthorize("hasAuthority('orderB:driverOil:list')")
    //@OperLog(value = "油卡", desc = "根据id查询")
    @ApiOperation("根据id查询油卡")
    @PostMapping("/get")
    public JsonResult get(DriverOil driverOil) {
        return driverOilService.getById(driverOil);
		// 使用关联查询
        //PageParam<driverOil> pageParam = new PageParam<>();
		//pageParam.put("id", id);
        //List<driverOil> records = driverOilService.listAll(pageParam.getNoPageParam());
        //return JsonResult.ok().setData(pageParam.getOne(records));
    }


    /**
     * 添加油卡
     */
    @PreAuthorize("hasAuthority('orderB:driverOil:save')")
    @OperLog(value = "油卡", desc = "添加", param = false, result = true)
    @ApiOperation(value ="添加油卡",notes = "" +
            "driverId:司机id\n" +
            "driver:司机姓名\n" +
            "carNo:车牌\n" +
            "oilCard:油卡号\n" +
            "usePrice: 油卡使用金额\n" +
//            "balancePrice:油卡余额\n" +
            "rechargePrice:油卡当前充值金额\n" +
            "rechargeDate:油卡充值日期\n" +
//            "cumulativePrice:油卡累计金额\n" +
            "remark:备注\n" +
        "",httpMethod = "POST")
    @PostMapping("/save")
    public JsonResult save(Model model, DriverOil driverOil) {
        return driverOilService.save(driverOil, getLoginUser());
    }

    /**
     * 修改油卡
     */
    @PreAuthorize("hasAuthority('orderB:driverOil:update')")
    @OperLog(value = "油卡", desc = "修改", param = false, result = true)
    @ApiOperation(value ="修改油卡",notes = "" +
            "id:id\n" +
            "driverId:司机id\n" +
            "driver:司机姓名\n" +
            "carNo:车牌\n" +
            "oilCard:油卡号\n" +
            "usePrice: 油卡使用金额\n" +
            "balancePrice:油卡余额\n" +
            "rechargePrice:油卡当前充值金额\n" +
            "rechargeDate:油卡充值日期\n" +
            "cumulativePrice:油卡累计金额\n" +
            "remark:备注\n" +
        "",httpMethod = "POST")
    @PostMapping("/update")
    public JsonResult update(Model model, DriverOil driverOil) {
        return driverOilService.update(driverOil, getLoginUser());
    }

    /**
     * 删除油卡
     */
//    @PreAuthorize("hasAuthority('orderB:driverOil:remove')")
//    @OperLog(value = "油卡", desc = "删除", result = true)
//    @ApiOperation("删除油卡")
//    @PostMapping("/remove")
//    public JsonResult remove(DriverOil driverOil ) {
//        return driverOilService.remove(driverOil, getLoginUser());
//    }

    /**
     * 批量添加油卡
     */
    /**@RequiresPermissions("orderB:driverOil:save")
    @OperLog(value = "油卡", desc = "批量添加", param = false, result = true)
    @ResponseBody
    @PostMapping("/saveBatch")
    public JsonResult saveBatch(@RequestBody List<DriverOil> list) {
        if (driverOilService.saveBatch(list)) {
            return JsonResult.ok("添加成功");
        }
        return JsonResult.error("添加失败");
    }*/

    /**
     * 批量修改油卡
     */
    /**@RequiresPermissions("orderB:driverOil:update")
    @OperLog(value = "油卡", desc = "批量修改", result = true)
    @ResponseBody
    @PostMapping("/updateBatch")
    public JsonResult updateBatch(@RequestBody BatchParam<DriverOil> batchParam) {
        if (batchParam.update(driverOilService, "")) {
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }*/

    /**
     * 批量删除油卡
     */
    /**@RequiresPermissions("orderB:driverOil:remove")
    @OperLog(value = "油卡", desc = "批量删除", result = true)
    @ResponseBody
    @PostMapping("/removeBatch")
    public JsonResult removeBatch(@RequestBody List<Integer> ids) {
        if (driverOilService.removeByIds(ids)) {
            return JsonResult.ok("删除成功");
        }
        return JsonResult.error("删除失败");
    }*/

}
